package weaver.interfaces.htsc.hrm;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.PasswordUtil;
import weaver.general.TimeUtil;
import weaver.general.Util;

import java.util.HashMap;
import java.util.Map;

public class OrganizationTimeSynHrm {

    /***
     * @param url
     */
    public Map<String,String> doHrmSyn(String url,String createTimeGreater,Map<String,String> headMap)
    {
        OrganizationSynUtil organizationSynUtil = new OrganizationSynUtil();
        OrganizationSyn organizationSynNew = new OrganizationSyn();
        int updatesuccesscount = 0;
        int updateerrorcount = 0;
        int insertsuccesscount = 0;
        int inserterrorcount = 0;
        int deletesuccesscount = 0;
        int deleteerrorcount = 0;
        int dataerrorcount = 0;
        int exceptioncount = 0;

        int updatedefinesuccesscount = 0;
        int updatedefineerrorcount = 0;
        int insertdefinesuccesscount = 0;
        int insertdefineerrorcount = 0;

        int allcount = 0;

        int page = 0;
        int pageSize = 300;
        Map<String,String> map = new HashMap<String,String>();
        RecordSet rs = new RecordSet();
        BaseBean bb = new BaseBean();

        bb.writeLog("OrganizationTimeSynHrm--doHrmSyn");
        String subcompanyid1 = organizationSynUtil.getSubcomIdByCode("HT0001");
        bb.writeLog("createTimeGreater:"+createTimeGreater);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("createTimeGreater",createTimeGreater);
        bb.writeLog("jsonObject:"+jsonObject.toJSONString());
        boolean hasNextPage = true;
        while(hasNextPage)
        {
            String response = "" ;
            try{
                String urlnew = url + "?page="+page+"&size="+pageSize ;
                bb.writeLog("urlnew:"+urlnew);
                response = organizationSynUtil.sendPost(urlnew,jsonObject.toJSONString(),headMap);
            }catch (Exception e){
                bb.writeLog("OrganizationSynTime-Exception-:"+e);
            }
            if(response !="" && !"".equals(response) && !"[]".equals(response))
            {
                JSONArray userArray = JSONArray.parseArray(response);
                bb.writeLog("userArray:"+userArray.size());
                allcount = allcount + userArray.size() ;

                for(int i=0;i<userArray.size();i++)
                {
                    JSONObject userJson = userArray.getJSONObject(i);
                    String empCode = Util.null2String(userJson.getString("empCode"));//员工编号
                    try{
                        String empName = Util.null2String(userJson.getString("empName"));//员工姓名

                        String empGender = Util.null2String(userJson.getString("empGender"));//员工性别
                        if ("女".equals(empGender)) {
                            empGender = "1";
                        } else {
                            empGender = "0";
                        }

                        String field8 = Util.null2String(userJson.getString("empEngName"));//员工英文名
                        String field1 = "";//微信大头像
                        String field2 = "";//微信小头像
                        String field0 = Util.null2String(userJson.getString("city"));//工作城市
                        String creator = Util.null2String(userJson.getString("creator"));//创建者工号
                        creator = organizationSynUtil.getUserIdByCode2Main(creator);
                        if ("".equals(creator)) {
                            creator = "1";
                        }
                        String accentEmail = Util.null2String(userJson.getString("accentEmail"));//主要邮箱
                        String accentMobile = Util.null2String(userJson.getString("accentMobile"));//主要手机
                        String accentPhone = Util.null2String(userJson.getString("accentPhone"));//主要座机
                        String field3 = Util.null2String(userJson.getString("empEmails"));//员工EMAIL
                        if (!"".equals(field3)) {
                            field3 = field3.replace("[", "").replace("]", "").replaceAll("\"", "");
                        }
                        String field4 = Util.null2String(userJson.getString("empMobiles"));//员工手机号
                        if (!"".equals(field4)) {
                            field4 = field4.replace("[", "").replace("]", "").replaceAll("\"", "");
                        }
                        String field5 = Util.null2String(userJson.getString("empPhones"));//员工固话
                        if (!"".equals(field5)) {
                            field5 = field5.replace("[", "").replace("]", "").replaceAll("\"", "");
                        }
                        String userState = Util.null2String(userJson.getString("userState"));//用户状态
                        int empSortNum = (0 - Util.getIntValue(userJson.getString("empSortNum"), 0));//员工排序号
                        String increStatus = Util.null2String(userJson.getString("increStatus"));//
                        String field6 = userJson.getString("state");//是否是外部联系人
                        String field7 = userJson.getString("comment");//备注
                        String field9 = Util.null2String(userJson.getString("empJobGrade"));//员工职级

                        String currentDate = TimeUtil.getCurrentDateString();//当前日期
                        String deptId = "";
                        String jobTitleId = "";
                        String textfield2 = "";
                        String empPositionNum = "";
                        //同步主岗数据
                        JSONObject primaryPosition = userJson.getJSONObject("primaryPosition");//主岗信息

                        if (primaryPosition != null)
                        {
                            organizationSynUtil.doJobTitleSyn(primaryPosition);
                            String deptCode = primaryPosition.getString("deptCode");
                            deptId = organizationSynUtil.getDeptIdByCode(deptCode);
                            String positionCode = primaryPosition.getString("positionCode");
                            if (!"".equals(positionCode) && !"".equals(deptId)) {
                                jobTitleId = organizationSynUtil.getJobTitleIdByCode(positionCode, deptId);
                            }
                            textfield2 = deptCode + ";" + positionCode + ";" + empCode;
                            empPositionNum = primaryPosition.getString("empPositionNum");
                        }

                        if ("ACTIVE".equalsIgnoreCase(userState)) {
                            userState = "1";
                        } else {
                            userState = "5";
                        }

                        int intresourceNum = 0;
                        try{
                            if(!"".equals(empPositionNum) && !"null".equals(empPositionNum) && empPositionNum !=null){
                                intresourceNum = Integer.parseInt(empPositionNum);
                            }else{
                                intresourceNum = -1;
                            }
                        }catch (Exception e){
                            bb.writeLog("OrganizationSyn-e:"+e);
                            intresourceNum = -2;
                        }

                        bb.writeLog("OrganizationTimeSynHrm-textfield2:"+textfield2+" & intresourceNum:"+intresourceNum+"&userState:"+userState);

                        if(intresourceNum >0)
                        {
                            if ("CREATE".equalsIgnoreCase(increStatus) || "UPDATE".equalsIgnoreCase(increStatus))
                            {
                                if (!"".equals(deptId) && !"".equals(jobTitleId))
                                {
                                    String userIdNum = organizationSynUtil.getUserIdByIntresourceNum(intresourceNum+"");
                                    String userId = organizationSynUtil.getUserIdByCode(empCode);  //主账号
                                    if (!"".equals(userId))
                                    {
                                        String userUpdateSql1 = " update hrmresource set lastname=?,departmentid=?,subcompanyid1=?,sex=?," +
                                                                " creater=?,email=?,mobile=?,telephone=?,jobtitle=?,status=?,dsporder=?,lastmoddate=?,modified=systimestamp,textfield2=?,belongto=null,accounttype=0 where id=? ";
                                        boolean flag = rs.executeUpdate(userUpdateSql1, new Object[]{empName, deptId, subcompanyid1, empGender, creator, accentEmail,
                                                accentMobile, accentPhone, jobTitleId, userState, empSortNum, currentDate, textfield2,userId});

                                        bb.writeLog("OrganizationTimeSynHrm-update & empCode="+empCode+" & flag="+flag);

                                        if (flag) {

                                            updatesuccesscount++;

                                            int cusFielddataId = organizationSynUtil.getCusFielddataId(intresourceNum+"", 1);
                                            if (cusFielddataId > 0) {
                                                String userUpdateSql2 = " update cus_fielddata set field0=?,field1=?,field2=?,field3=?,field4=?," +
                                                                        " field5=?,field6=?,field7=?,field8=?,field9=? where scope='HrmCustomFieldByInfoType' and scopeid=1 and id=?";

                                                //bb.writeLog(userUpdateSql2);
                                                boolean deflag = rs.executeUpdate(userUpdateSql2, new Object[]{field0, field1, field2, field3, field4, field5, field6, field7, field8, field9, intresourceNum});
                                                if(deflag){
                                                    updatedefinesuccesscount++;
                                                }else{
                                                    updatedefineerrorcount++;
                                                }
                                            } else {
                                                String userInsertSql2 = " insert into cus_fielddata (scope,scopeid,id,field0,field1,field2,field3," +
                                                        " field4,field5,field6,field7,field8,field9) values('HrmCustomFieldByInfoType',1,?,?,?,?,?,?,?,?,?,?,?)";
                                                bb.writeLog(userInsertSql2);
                                                boolean deflag = rs.executeUpdate(userInsertSql2, new Object[]{intresourceNum, field0, field1, field2, field3, field4, field5, field6, field7, field8, field9});

                                                if(deflag){
                                                    insertdefinesuccesscount++;
                                                }else{
                                                    insertdefineerrorcount++;
                                                }
                                            }
                                        } else {
                                            updateerrorcount++;
                                        }

                                        if(!userIdNum.equals(userId)){
                                            if("1".equals(userState)){
                                                bb.writeLog("dataiderroecountACTIVE--empCode:"+empCode+" deptId:"+deptId+" jobTitleId:"+jobTitleId);
                                            }else{
                                                bb.writeLog("dataiderroecountDELETE--empCode:"+empCode+" deptId:"+deptId+" jobTitleId:"+jobTitleId);
                                            }
                                        }
                                    } else {

                                        PropBean pb = new PropBean();
                                        String dynapass = Util.null2String(pb.getPropName( "PASSWORD"),"Ht123456!");
                                        String[] pwdArr = PasswordUtil.encrypt(dynapass);
                                        String newPWD = pwdArr[0];

                                        rs.executeProc("HrmResourceMaxId_Get", "");
                                        rs.next();
                                        userId = rs.getInt(1) + "";

                                        String userInsertSql1 = " insert into hrmresource(id,loginid,password,workcode,lastname,departmentid,subcompanyid1,sex," +
                                                                " creater,email,mobile,telephone,jobtitle,status,dsporder,systemlanguage,createdate,lastmoddate,created,modified,textfield2,belongto,accounttype) " +
                                                                " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,systimestamp,systimestamp,?,?,?)";
                                        boolean flag = rs.executeUpdate(userInsertSql1, new Object[]{userId, empCode, newPWD, empCode, empName, deptId, subcompanyid1, empGender,
                                                creator, accentEmail, accentMobile, accentPhone, jobTitleId, userState, empSortNum, 7, currentDate, currentDate, textfield2,"null","0"});

                                        bb.writeLog("OrganizationTimeSynHrm-insert & empCode:"+empCode+" & flag:"+flag);
                                        if(flag)
                                        {
                                            insertsuccesscount++;

                                            try{
                                                String sql = " update hrmresource set id=" + intresourceNum + " where id=" + userId;
                                                boolean flag2 = rs.execute(sql);
                                                bb.writeLog("OrganizationTimeSynHrm-id-update & empCode:"+empCode+" &--2--flag="+flag2);
                                                if(flag2)
                                                {
                                                    try {
                                                        int cusFielddataId = organizationSynUtil.getCusFielddataId(intresourceNum+"", 1);
                                                        if (cusFielddataId > 0) {
                                                            String userUpdateSql2 = " update cus_fielddata set field0=?,field1=?,field2=?,field3=?,field4=?," +
                                                                    " field5=?,field6=?,field7=?,field8=?,field9=? where scope='HrmCustomFieldByInfoType' and scopeid=1 and id=?";
                                                            boolean deflag = rs.executeUpdate(userUpdateSql2, new Object[]{field0, field1, field2, field3, field4, field5, field6, field7, field8, field9, userId});
                                                            if(deflag){
                                                                updatedefinesuccesscount++;
                                                            }else{
                                                                updatedefineerrorcount++;
                                                            }
                                                        } else {
                                                            String userInsertSql2 = " insert into cus_fielddata (scope,scopeid,id,field0,field1,field2,field3," +
                                                                    " field4,field5,field6,field7,field8,field9) values('HrmCustomFieldByInfoType',1,?,?,?,?,?,?,?,?,?,?,?)";
                                                            boolean deflag = rs.executeUpdate(userInsertSql2, new Object[]{userId, field0, field1, field2, field3, field4, field5, field6, field7, field8, field9});
                                                            if(deflag){
                                                                insertdefineerrorcount++;
                                                            }else{
                                                                insertdefinesuccesscount++;
                                                            }
                                                        }
                                                        organizationSynNew.updateColList(intresourceNum+"");
                                                    } catch (Exception e) {
                                                        bb.writeLog("OrganizationSynTime-Exception-:"+e);
                                                        bb.writeLog("e:" + e);
                                                    }
                                                }
                                            }catch (Exception e){
                                                bb.writeLog("OrganizationSynTime-Exception-:"+e);
                                                bb.writeLog("OrganizationTimeSynHrm-dataiderrorcount--empCode:"+empCode+" deptId:"+deptId+" jobTitleId:"+jobTitleId);
                                                exceptioncount ++ ;
                                            }
                                        } else {
                                            inserterrorcount++;
                                        }
                                    }

                                    if ("1".equalsIgnoreCase(userState)) {
                                        bb.writeLog("userState:"+userState+"-----photo");
                                        String photo = Util.null2String(userJson.getString("photo"));//员工编号
                                        organizationSynUtil.synHrmPhoto(empCode, photo, intresourceNum+"");
                                    }

                                }else{
                                    if("1".equalsIgnoreCase(userState)){
                                        bb.writeLog("OrganizationTimeSynHrm-dataerrorcountACTIVE--empCode:"+empCode+" deptId:"+deptId+" jobTitleId:"+jobTitleId);
                                    }else{
                                        bb.writeLog("OrganizationTimeSynHrm-dataerrorcountDELETE--empCode:"+empCode+" deptId:"+deptId+" jobTitleId:"+jobTitleId);
                                    }
                                    dataerrorcount++;
                                }


                            } else if ("DELETE".equalsIgnoreCase(increStatus))
                            {
                                if (!"".equals(deptId) && !"".equals(jobTitleId))
                                {
                                    String userIdNum = organizationSynUtil.getUserIdByIntresourceNum(intresourceNum+"");
                                    String userId = organizationSynUtil.getUserIdByCode(empCode);  //主账号
                                    rs.writeLog(empCode + ":" + userId + ":DELETE");
                                    if (!"".equals(userId)) {
                                        String userUpdateSql1 = " update hrmresource set status=5,lastmoddate=?,modified=systimestamp where id=? ";
                                        boolean flag = rs.executeUpdate(userUpdateSql1, new Object[]{currentDate, userId});
                                        if (flag) {
                                            deletesuccesscount++;
                                        } else {
                                            deleteerrorcount++;
                                        }
                                    }

                                    if(!userIdNum.equals(userId)){
                                        bb.writeLog("dataiderroecountDELETE--empCode:"+empCode+" deptId:"+deptId+" jobTitleId:"+jobTitleId);
                                    }
                                }else{
                                    bb.writeLog("OrganizationTimeSynHrm-dataerrorcount--empCode:"+empCode+" deptId:"+deptId+" jobTitleId:"+jobTitleId);
                                    dataerrorcount++;
                                }
                            }
                        }else{
                            bb.writeLog("OrganizationTimeSynHrm-dataerrorcount--empCode="+empCode+" intresourceNum:"+empPositionNum);
                            dataerrorcount++;
                        }
                    }catch (Exception e){
                        bb.writeLog("OrganizationSynTime-Exception-:"+e);
                        e.printStackTrace();
                        rs.writeLog("人员编号"+empCode+"的数据同步失败，data:"+userJson.toJSONString());
                        exceptioncount ++ ;
                    }
                }
                if(userArray.size()<pageSize)
                {
                    hasNextPage = false;
                }
                page++;
            }else{
                bb.writeLog("777777777777777");
                hasNextPage = false;
            }
        }

        map.put("updateerrorcount",updateerrorcount+"");
        map.put("updatesuccesscount",updatesuccesscount+"");
        map.put("insertsuccesscount",insertsuccesscount+"");
        map.put("inserterrorcount",inserterrorcount+"");
        map.put("deletesuccesscount",deletesuccesscount+"");
        map.put("deleteerrorcount",deleteerrorcount+"");
        map.put("exceptioncount",exceptioncount+"");
        map.put("dataerrorcount",dataerrorcount+"");

        map.put("updatedefinesuccesscount",updatedefinesuccesscount+"");
        map.put("updatedefineerrorcount",updatedefineerrorcount+"");
        map.put("insertdefinesuccesscount",insertdefinesuccesscount+"");
        map.put("insertdefineerrorcount",insertdefineerrorcount+"");

        map.put("allcount",allcount+"");
        return map;
    }



    /***
     * 同步岗位数据及此账号
     */
    public Map<String,String> doPositionSyn(String url,String createTimeGreater,Map<String,String> headMap)
    {
        Map<String,String> map = new HashMap<String,String>();

        OrganizationSynUtil organizationSynUtil = new OrganizationSynUtil();
        OrganizationSynHrm organizationSynNew = new OrganizationSynHrm();
        BaseBean bb = new BaseBean();
        bb.writeLog("------doPositionSyn-------");
        int updatesuccesscount = 0;
        int updateerrorcount = 0;
        int insertsuccesscount = 0;
        int inserterrorcount = 0;
        int exceptioncount = 0;
        int dataerrorcount = 0;
        int allcount = 0;
        int updatedefinesuccesscount = 0;
        int updatedefineerrorcount = 0;
        int insertdefinesuccesscount = 0;
        int insertdefineerrorcount = 0;

        int nullcount = 0;

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("createTimeGreater",createTimeGreater);
        int page = 0;
        int pageSize = 300;
        try{

            boolean hasNextPage = true;
            while (hasNextPage) {
                String response = "" ;
                try {
                    String urlnew = url+"?page="+page+"&size="+pageSize ;
                    bb.writeLog("urlnew",urlnew);
                    response = organizationSynUtil.sendPost(urlnew,jsonObject.toJSONString(),headMap);
                }catch (Exception e){
                    bb.writeLog("OrganizationSynTime-Exception-:"+e);
                }

                if(!"".equals(response))
                {
                    JSONArray positionArray = JSONArray.parseArray(response);
                    if(positionArray.size() >0)
                    {
                        allcount = allcount + positionArray.size();
                        for (int i = 0; i < positionArray.size(); i++)
                        {
                            JSONObject positionJson = positionArray.getJSONObject(i);
                            String positionType = Util.null2String(positionJson.get("positionType"));
                            organizationSynUtil.doJobTitleSyn(positionJson);
                            if("0".equals(positionType))
                            {
                                //住账号的岗位数据同步
                                int count = doMainAccountSynTime(positionJson);
                                if(count == 1){
                                    updatesuccesscount++;
                                }else if(count == -1){
                                    updateerrorcount++;
                                }else if(count == -3){
                                    dataerrorcount++;
                                }else if(count == -2){
                                    exceptioncount++;
                                }
                            }else{
                                allcount++;
                                //次账号的岗位数据同步
                                int count = organizationSynNew.doSecAccountSynTime(positionJson);
                                if(count == -10){
                                    updateerrorcount++;
                                }else if(count == -11){
                                    inserterrorcount++;
                                }else if(count == -3){
                                    dataerrorcount++;
                                }else if(count == -2){
                                    exceptioncount++;
                                }else if(count == -100){
                                    nullcount++;
                                }else if(count == -12){
                                    updatedefinesuccesscount++;
                                    updatesuccesscount++;
                                }else if(count == -13){
                                    updatedefineerrorcount++;
                                    updateerrorcount++;
                                }else if(count == -14){
                                    insertdefinesuccesscount++;
                                    insertsuccesscount++;
                                }else if(count == -15){
                                    insertdefineerrorcount++;
                                    inserterrorcount++;
                                }
                            }
                        }
                    }else{
                        hasNextPage = false;
                    }
                }else{
                    hasNextPage = false;
                }
                page++;
            }
            bb.writeLog("###############allcount:"+allcount);
        }catch (Exception e){
            bb.writeLog("OrganizationSyn-e:"+e);
        }

        map.put("updatesuccesscount",updatesuccesscount+"");
        map.put("updateerrorcount",updateerrorcount+"");
        map.put("insertsuccesscount",insertsuccesscount+"");
        map.put("inserterrorcount",inserterrorcount+"");
        map.put("exceptioncount",exceptioncount+"");
        map.put("dataerrorcount",dataerrorcount+"");
        map.put("updatedefinesuccesscount",updatedefinesuccesscount+"");
        map.put("updatedefineerrorcount",updatedefineerrorcount+"");
        map.put("insertdefinesuccesscount",insertdefinesuccesscount+"");
        map.put("insertdefineerrorcount",insertdefineerrorcount+"");
        map.put("nullcount",nullcount+"");
        map.put("allcount",allcount+"");

        return map;
    }

    /**
     *
     * @param userJson
     */
    public int doMainAccountSynTime(JSONObject userJson)
    {
        int count = 0;
        BaseBean bb = new BaseBean();
        PropBean pb = new PropBean();
        OrganizationSynUtil organizationSynUtil = new OrganizationSynUtil();
        RecordSet rs = new RecordSet();
        String HT0001 = pb.getPropName("HT0001");

        try{
            String subcompanyid1 = organizationSynUtil.getSubcomIdByCode(HT0001);

            if(userJson !=null)
            {
                String empCode = Util.null2String(userJson.getString("empCode"));//员工编号
                String positionCode = Util.null2String(userJson.getString("positionCode"));//员工编号
                String deptCode = Util.null2String(userJson.getString("deptCode"));//员工编号
                String strsafeLevel = Util.null2String(userJson.getString("safeLevel"));
                int safeLevel = 0;
                if(!"".equals(strsafeLevel)){
                    safeLevel = Util.getIntValue(strsafeLevel);//安全级别
                }

                String empRealWorkCity = Util.null2String(userJson.getString("empRealWorkCity"));
//                bb.writeLog("empRealWorkCity:"+empRealWorkCity);
                String empPositionNum = "";
                long intresourceNum = 0;
                try{
                    empPositionNum = Util.null2String(userJson.getString("empPositionNum"));
                    if(!"".equals(empPositionNum) && !"null".equals(empPositionNum) && empPositionNum !=null){
                        intresourceNum = Long.parseLong(empPositionNum);
                    }else{
                        intresourceNum = -1;
                    }
                }catch (Exception e){
                    bb.writeLog("OrganizationSyn-e:"+e);
                    intresourceNum = -2;
                }

                if(!"".equals(positionCode) && !"".equals(deptCode))
                {
                    String deptId = organizationSynUtil.getDeptIdByCode(deptCode);
                    String jobTitleId = organizationSynUtil.getJobTitleIdByCode(positionCode,deptId);
                    String jobState = Util.null2String(userJson.getString("jobState"));//员工编号
                    String empJobLevel = Util.null2String(userJson.getString("empJobLevel"));//员工编号
//                    if("ACTIVE".equalsIgnoreCase(jobState))
//                    {
//                        jobState = "1";
//                    }else{
//                        jobState = "5";
//                    }
                    String textfield2 = deptCode+";"+positionCode+";"+empCode;

                    String userId = organizationSynUtil.getUserIdByCode(empCode);

                    bb.writeLog("doMainAccountSynTime & empCode:"+empCode+" deptCode:"+deptCode+" positionCode:"+positionCode+"&strsafeLevel:"+strsafeLevel+"&jobState="+jobState +" userId="+userId+" intresourceNum="+intresourceNum +" empPositionNum="+empPositionNum);

                    if(!"".equals(userId) && userId.equals(intresourceNum+"") && "ACTIVE".equalsIgnoreCase(jobState))
                    {
                        //人员已存在，更新操作
                        String userUpdateSql1 = " update hrmresource set seclevel="+safeLevel+"  where id="+userId+"";
                        bb.writeLog("userUpdateSql1:"+userUpdateSql1);
                        boolean flag = rs.executeUpdate(userUpdateSql1);
                        bb.writeLog("doMainAccountSynTime---flag:"+flag);
                        if(flag)
                        {
                            String userDataSql = " update cus_fielddata set field11='"+empRealWorkCity+"',field12='"+empJobLevel+"' where id in(select id from hrmresource where workcode='"+empCode+"' and status=1) and scopeid=1 and scope='HrmCustomFieldByInfoType'";
                            boolean defflag = rs.executeUpdate(userDataSql);
                            if(defflag){
                                count = 1;
                            }
                        }else{
                            count = -1;
                        }
                    }
                }else
                {
                    count = -3;
                    bb.writeLog("dataerrorcount--empCode:"+empCode);
                }
            }
        }catch (Exception e){
            bb.writeLog("OrganizationSyn-e:"+e);
            count = -2;
        }
        return count;
    }


}
